Skip to content

[codex] Fix steady state callback interval handling#1180

Open
svchb wants to merge 7 commits into
trixi-framework:mainfrom
svchb:codex/fix-steady-state-callback
Open

[codex] Fix steady state callback interval handling#1180
svchb wants to merge 7 commits into
trixi-framework:mainfrom
svchb:codex/fix-steady-state-callback

Conversation

@svchb
Copy link
Copy Markdown
Collaborator

@svchb svchb commented May 11, 2026

Summary

  • respect interval before evaluating the steady-state kinetic-energy condition
  • normalize integer tolerances to floating-point values so the callback can be constructed with integer inputs
  • reject non-positive interval_size values

Root Cause

The discrete callback condition called steady_state_condition! directly, so interval was never checked. The constructor also chose the previous kinetic-energy vector element type before converting tolerances to a floating type, which made integer tolerances try to store Inf as an integer.

Validation

  • julia --project=. -e 'using Test, TrixiParticles; include("test/callbacks/steady_state_reached.jl")'

@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.93%. Comparing base (5d46487) to head (4a2beee).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1180      +/-   ##
==========================================
+ Coverage   89.88%   89.93%   +0.04%     
==========================================
  Files         133      134       +1     
  Lines       10452    10480      +28     
==========================================
+ Hits         9395     9425      +30     
+ Misses       1057     1055       -2     
Flag Coverage Δ
total 89.93% <100.00%> (+0.04%) ⬆️
unit 70.52% <74.35%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@svchb svchb self-assigned this May 12, 2026
@svchb svchb requested a review from efaulhaber May 12, 2026 11:09
@svchb svchb added the bug Something isn't working label May 12, 2026
@svchb svchb marked this pull request as ready for review May 12, 2026 11:09
Comment thread src/callbacks/steady_state_reached.jl Outdated
Comment thread src/callbacks/steady_state_reached.jl Outdated
Comment thread src/callbacks/steady_state_reached.jl
Co-authored-by: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com>
@svchb svchb requested a review from efaulhaber May 18, 2026 10:41

# Keywords
- `interval=0`: Check steady state condition every `interval` time steps.
A value of `0` disables step-interval checks.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A value of `0` disables step-interval checks.
Use either `interval` or `dt`.

(note that this may change the solution).
- `interval_size`: The interval in which the change of the kinetic energy is considered.
`interval_size` is a (integer) multiple of `interval` or `dt`.
- Either `interval` or `dt` must be set to something larger than 0.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Either `interval` or `dt` must be set to something larger than 0.
Use either `interval` or `dt`.


function initialize_steady_state_callback!(cb::SteadyStateReachedCallback, u, t, integrator)
semi = integrator.p.semi
set_callbacks_used!(semi, integrator)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

empty!(cb.previous_ekin)
push!(cb.previous_ekin, convert(eltype(cb.previous_ekin), Inf))

return nothing
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nothing
return cb

Comment on lines +90 to +91
if !steady_state_condition!(cb, integrator)
u_modified!(integrator, false)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if !steady_state_condition!(cb, integrator)
u_modified!(integrator, false)
u_modified!(integrator, false)
if !steady_state_condition!(cb, integrator)

Do we even need u_modified! in the condition? Have you checked this?

Comment on lines +99 to +100
u_modified!(integrator, false)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
u_modified!(integrator, false)


u_modified!(integrator, false)

return nothing
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nothing
return cb


u_modified!(integrator, false)

return nothing
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nothing
return cb


# `condition` (`DiscreteCallback`)
function (steady_state_callback::SteadyStateReachedCallback{Int})(vu_ode, t, integrator)
condition_steady_state_interval(steady_state_callback, integrator) || return false
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
condition_steady_state_interval(steady_state_callback, integrator) || return false
if condition_integrator_interval(integrator, cb.interval; save_final_solution=false)
return false
end

No need for an extra function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants